/**
 * @description 新增、编辑功能项组弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Checkbox, Form, Input, Modal, Radio} from 'antd';

const FormItem = Form.Item;
const RadioGroup = Radio.Group;

class FeatureModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            modalVisible: false,
            confirmLoading: false,
            featureType: ""
        }
    }

    handleClose = () => {
        this.props.form.resetFields();
    };

    componentWillReceiveProps(nextProp) {
        const {defaultValue} = nextProp;
        if (defaultValue&&defaultValue.featureType)
            this.setState({featureType: defaultValue.featureType})
    }

    componentDidMount() {
        this.props.onRef(this);
    }

    checkFeatureType = (rule, value, callback) => {
        if (value === "Operate") {
            this.props.form.setFieldsValue({
                'biddingCondition.confirmTypeEnum': 'ConfirmByRate',
                'biddingCondition.canChooseQuoted': false
            });
        }
        callback();
    };

    render() {
        const formItemLayout = {
            labelCol: {
                span: 8
            },
            wrapperCol: {
                span: 12
            },
        };

        const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue, rightFlag,featureGroupId} = this.props;
        const {getFieldDecorator} = this.props.form;
        let childId = "";
        let FormValue = defaultValue;
        let title = "编辑功能项";
        if (rightFlag==="refAdd"){
            title = "参考创建";
        }else if (rightFlag==="add") {
            title = "新增功能项";
            FormValue = {}
        }
        return (
            <div>
                <Modal title={title}
                       visible={modalVisible}
                       onOk={handleOk}
                       onCancel={handleCancel}
                       width={600}
                       afterClose={this.handleClose}
                       confirmLoading={confirmLoading}
                       maskClosable={false}
                >
                    <Form>
                        <FormItem
                            {...formItemLayout}
                            label="功能项类型"
                            style={{display: "none"}}
                        >
                            {getFieldDecorator('featureType', {
                                initialValue: "Page",
                            })(
                                <Input disabled/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="代码"
                        >
                            {getFieldDecorator('code', {
                                initialValue: FormValue.code ? FormValue.code : "",
                              rules: [{required: true, message: '请填写代码!',whitespace:true}]
                            })(
                                <Input/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="名称">
                            {getFieldDecorator('name', {
                                initialValue: FormValue.name ? FormValue.name : "",
                                rules: [{required: true, message: '请填写名称!'}]
                            })(
                                <Input/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="资源">
                            {getFieldDecorator('url', {
                                initialValue: FormValue.url ? FormValue.url : "",
                                rules: [{required: true, message: '请填写资源!'}]
                            })(
                                <Input/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="是否为菜单项">
                            {getFieldDecorator('canMenu', {
                                valuePropName: 'checked',
                                initialValue: FormValue.canMenu ? FormValue.canMenu : false,
                            })(
                                <Checkbox/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="租户是否可用">
                            {getFieldDecorator('tenantCanUse', {
                                valuePropName: 'checked',
                                initialValue: FormValue.tenantCanUse ? FormValue.tenantCanUse : false,
                            })(
                                <Checkbox/>
                            )}
                        </FormItem>
                        {/*以下为隐藏的formItem*/}
                        <FormItem
                        style={{display: "none"}}>
                        {getFieldDecorator('id', {
                            initialValue: FormValue.id ? FormValue.id : "",
                        })(
                            <Input disabled/>
                        )}
                    </FormItem>
                        <FormItem
                            style={{display: "none"}}>
                            {getFieldDecorator('featureGroup.id', {
                                initialValue: featureGroupId ? featureGroupId : "",
                            })(
                                <Input disabled/>
                            )}
                        </FormItem>
                    </Form>
                </Modal>
            </div>
        );
    }
}

FeatureModal = Form.create()(FeatureModal);
export default FeatureModal;
